let user_name = "";
// const getUserNameUrl = "http://localhost:8081/xzy/sysParams/getUserName";
const getUserNameUrl = "sysParams/getUserName";
const INVALID_FIRST_LEVEL_MENU_SYMBOL = '/';

$(function(){
    writeLocalStorage_userName();// 初始化获取当前登录用户的用户名
})

// 请求后端获取用户名称
function writeLocalStorage_userName(){
    $.ajax({
        url: getUserNameUrl,
        type: 'GET',
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            if( !data ) {
                localStorage.setItem("GLOBAL_SYS_PARAMS_USER_NAME",userName);
            }else{
                const userName = data.userName || "";
                localStorage.setItem("GLOBAL_SYS_PARAMS_USER_NAME",userName)
            }

        },
        error: function(e){
            console.log('请求后端获取用户名称时出现异常');
            console.log(e.status);
            console.log(e.responseText);
        },
        complete: function(){
            const userName = localStorage.getItem("GLOBAL_SYS_PARAMS_USER_NAME");
            if( !userName )
                localStorage.setItem("GLOBAL_SYS_PARAMS_USER_NAME","");
        }
    })
}

// 获取当前登录系统的用户名，不是工号
// 加入登录的工号是1007 ，则用户名是：工藤工厂长
function getLocalStorage_userName(){
    return localStorage.getItem('GLOBAL_SYS_PARAMS_USER_NAME')||'';
}

function isAdmin(username){
    if(username === '超级管理员' || username === '工藤荣峰' || username === '金浩') return true;
    else return false;
}